<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script>

    var arr = [6, 4, 5, 4, 3, 7, 8];
    var sum = 0;
    for (var i = 0;i <arr.length;i++){
        sum += arr[i];
    }
    document.write('sum ='+ sum);


    sum = 0;
    for (var i = 0; i < arr.length; i++){
        if (arr[i] % 2 ==0){
            sum += arr[i];
        }
    }
    document.write('<br>');
    document.write('sum ='+ sum);

//    找出数组中的最大数
    function maxArray(arr) {
        var max = arr[0];
        for(var i =1; i < arr.length;i++){
            max = max > arr[i] ? max : arr[i];
        }
        return max;
    }

    var max = maxArray(arr);

//    调换数组中元素的位置
    function swapArray(arr) {

    //    数组元素的个数
        var len = arr.length;
    //    交换的次数
    //    math.floor() 向下取整
        var n = Math.floor(len/2);

        for (var i =0;i < n; i++ ){
            var temp =arr[i];
            arr[i] = arr[len -1 -i];
            arr[len - 1- i]= temp;
        }
    }

    arr = [1,2,3,4,5,6];
    swapArray(arr);
    console.log(arr);
    document.write(arr);
</script>